package presenter;

import java.util.Observer;

import bean.login_bean.PersonDataBean;
import interfaces.IUserInfoInterface;
import responsitory.UserResponsitory;
import util.volley.ICompleteListener;
import util.volley.ResultEntity;

/**
 * Created by admin on 2016/11/28.
 */

public class UserPresenter extends BasePresenter implements
        IUserInfoInterface<PersonDataBean> {
    // 用户登录
    public static final String login_success = UserPresenter.class.getName()
            + "_User_success";
    public static final String login_fail = UserPresenter.class.getName()
            + "_User_fail";

    //注册
    public static final String register_fail = UserPresenter.class.getName()
            + "_Register_fail";
    public static final String register_success = UserPresenter.class.getName()
            + "_Register_success";
    //发送验证码
    public static String send_code_fail = "_Send_code_fail";
    public static String send_code_success = "_Send_code_success";
    //验证验证码
    public static String yanzheng_code_fail = "_yanzheng_code_fail";
    public static String yanzheng_code_success = "_yanzheng_code_success";
    //修改密码（通过验证码）
    public static String updata_pass_success = "_updata_pass_success";
    public static String updata_pass_fail = "_updata_pass_fail";
    //修改个人信息
    public static String updata_xinxi_success = "_updata_xinxi_success";
    public static String updata_xinxi_fail = "_updata_xinxi_fail";
    //修改密码（通过旧密码）
    public static String modify_pass_success = "_modify_pass_success";
    public static String modify_pass_fail = "_modify_pass_fail";
    //查询收货地址
    public static String query_address_success = "_query_address_success";
    public static String query_address_fail = "_query_address_fail";
    //添加收货地址
    public static String add_address_success = "_add_address_success";
    public static String add_address_fail = "_add_address_fail";
    //删除收货地址
    public static String delete_address_success = "_delete_address_success";
    public static String delete_address_fail = "_delete_address_fail";
    //更新收货地址
    public static String update_address_success = "_update_address_success";
    public static String update_address_fail = "_update_address_fail";

    //司机认证
    public static String renzheng_success = "_renzheng_success";
    public static String renzheng_fail = "_renzheng_fail";


    //技工认证
    public static String jg_success = "_jg_success";
    public static String jg_fail = "_jg_fail";
    //地理位置更新
    public static String weizhiUpdate_success = "_weizhiUpdate_success";
    public static String weizhiUpdate_fail = "_weizhiUpdate_fail";


    //获取配置
    public static String config_success = "_config_success";
    public static String config_fail = "_config_fail";


    //批量添加购物车
    public static String addAll_success = "_addAll_success";
    public static String addAll_fail = "_addAll_fail";
    //获取默认收货地址
    public static String moren_address_success = "_moren_address_success";
    public static String moren_address_fail = "_moren_address_fail";
    public UserPresenter(Observer observer) {
        super(observer);
    }

    @Override
    public void login(String username, String pwd) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(login_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(login_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.login(username, pwd);
    }

    @Override
    public void getMoRenAddress(String s_id,String uid) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(moren_address_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(moren_address_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.getMoRenAddress(s_id,uid);
    }

    @Override
    public void addMallAll(String uid, String id, String sku_pkid, String count) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(addAll_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(addAll_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.addMallAll(uid, id,sku_pkid,count);
    }

    @Override
    public void register(String username, String pwd, String country, String code, String from) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(register_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(register_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.register(username, pwd,country,code,from);
    }

    @Override
    public void sendVerificationCode(String country, String mobile, String code_type) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(send_code_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(send_code_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.sendVerificationCode(country, mobile, code_type);
    }

    @Override
    public void YanZhengverificationCode(String country, String mobile, String code, String code_type) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(yanzheng_code_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(yanzheng_code_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.YanZhengverificationCode(country, mobile,code, code_type);
    }

    @Override
    public void queryAddress(String s_id,String uid) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(query_address_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(query_address_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.queryAddress(s_id,uid);
    }

    @Override
    public void deleteAddress(String s_id,String uid, String id) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(delete_address_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(delete_address_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.deleteAddress(s_id,uid,id);
    }
    @Override
    public void updatePass(String country, String code, String mobile, String password) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(updata_pass_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(updata_pass_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.updatePass(country, code,mobile,password);
    }

    @Override
    public void upadtaInformation(String uid, String types, String content) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(updata_xinxi_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(updata_xinxi_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.upadtaInformation(uid, types,content);
    }

    @Override
    public void modifyPass(String uid, String password, String new_password) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(modify_pass_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(modify_pass_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.modifyPass(uid, password,new_password);
    }

    @Override
    public void addressAdd(String s_id,String uid, String contactname, String mobile,String postal_code, String province, String city, String area, String detailinfo, String defaults,String country,String country_id) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(add_address_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(add_address_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.addressAdd(s_id,uid, contactname,mobile,postal_code,province,city,area,detailinfo,defaults,country,country_id);
    }

    @Override
    public void updateAddress(String s_id,String id, String uid, String contactname, String mobile, String postal_code, String province, String city, String area, String detailinfo, String defaults, String country, String country_id) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(update_address_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(update_address_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.updateAddress(s_id,id,uid, contactname,mobile,postal_code,province,city,area,detailinfo,defaults,country,country_id);
    }

    @Override
    public void sijiRenZheng(String uid, String id_number, String realname, String id_certs) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(renzheng_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(renzheng_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.sijiRenZheng(uid, id_number,realname,id_certs);
    }

    @Override
    public void jigongRenZheng(String uid, String skills) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(jg_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(jg_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.jigongRenZheng(uid, skills);
    }

    @Override
    public void weiZhiUpdate(String id, String lat, String lng,String s_id) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(weizhiUpdate_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(weizhiUpdate_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.weiZhiUpdate(id, lat,lng,s_id);
    }
    @Override
    public void getConfigApp() {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(config_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(config_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.getConfigApp();
    }
    public static String updatepwdbypwd_success="_updatepwdbypwd_success";
    public static String updatepwdbypwd_fail="_updatepwdbypwd_fail";

    @Override
    public void updatePwdByPwd(String uid, String oldPass, String newPass) {
        IUserInfoInterface<PersonDataBean> user = new UserResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(updatepwdbypwd_success);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(updatepwdbypwd_fail);
                        UserPresenter.this.setChanged();
                        UserPresenter.this.notifyObservers(result);

                    }
                });
        user.updatePwdByPwd(uid,oldPass,newPass);
    }
}
